﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.IO;
using System.Web;
using System.Threading.Tasks;
using System.Data;
using BartonExtension;
using ResponseObject;
using SQLWrapper;
using Model.App;
using Model.Images;
using Model.Weixin;
using Services.Common;
using Services.User;

namespace iShangMai.Controllers
{
    public class BlacklistController : ApiController
    {
        [HttpGet]
        public async Task<ZKResponse> GetBlacklist(UInt64 uid,string token)
        {
            ZKResponse response = new ZKResponse();
            Dictionary<string, object> param = new Dictionary<string, object>();
            param.Add("uid", uid);
            param.Add("token", token);

            ISMServiceModel model = new ISMServiceModel()
            {
                operationIdentifier = ISMBlacklistServiceProvider.GET_BLACK_LIST,
                userinfo = param
            };
            ISMBlacklistServiceProvider provider = (ISMBlacklistServiceProvider)ISMServiceStack.sharedInstance[ISMServiceStackKeys.BLACKLIST];
            var result = await provider.doProcess(model);
            response.isProcessSuccess = result.isOperationSuccess;
            response.errMsg = result.errorMsg;
            response.userinfo = result.dbReturningState;
            return response;
        }
        [HttpPost]
        public async Task<ZKResponse> SetUserBlockStatus(ISMBlockUserRequest request)
        {
            ZKResponse response = new ZKResponse();
            ISMServiceModel model = new ISMServiceModel()
            {
                operationIdentifier = request.setBlock ? ISMBlacklistServiceProvider.ADD_TO_BLACKLIST : 
                                                         ISMBlacklistServiceProvider.REMOVE_FROM_BLACKLIST,
                userinfo = request
            };
            ISMBlacklistServiceProvider provider = (ISMBlacklistServiceProvider)ISMServiceStack.sharedInstance[ISMServiceStackKeys.BLACKLIST];
            var result = await provider.doProcess(model);
            response.isProcessSuccess = result.isOperationSuccess;
            response.errMsg = result.errorMsg;
            response.userinfo = result.dbReturningState;
            return response;
        }
    }
}
